package com.jzr.bedside.ui.adapter

import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.jzr.bedside.R
import com.jzr.bedside.bean.CheckedListBean
import com.jzr.bedside.bean.CheckedListBean.Answer
import com.jzr.bedside.bean.TQuestionBean
import java.util.*


class EvaluateApadter(data: MutableList<TQuestionBean.DataBean>?) :
    BaseQuickAdapter<TQuestionBean.DataBean, BaseViewHolder>(
        R.layout.item_evaluate,
        data
    ) {

    private var evaluateChildrenApadter: EvaluateChildrenApadter? = null
    private val checkedList = mutableListOf<CheckedListBean>()

    fun getCheckedList(): List<CheckedListBean?>? {
        return checkedList
    }

    fun addCheckedList(item: Answer?, postion: Int) {
        checkedList[postion].answers = item
    }

    fun removeCheckedList(item: Answer, postion: Int) {
        checkedList[postion].answers = item
    }

    override fun convert(helper: BaseViewHolder?, item: TQuestionBean.DataBean?) {
        helper!!.setText(R.id.tvName, item?.title)
        val checkedListBean = CheckedListBean()
        val answerList: Answer = Answer()
        checkedListBean.title = item?.title
        checkedListBean.titleId = item?.controlId!!
        checkedListBean.answers = answerList
        checkedList.add(checkedListBean)

        evaluateChildrenApadter = EvaluateChildrenApadter(
            item.options,
            helper.layoutPosition, item.type, this
        )

        val childrenRv = helper.getView<RecyclerView>(R.id.rvChildren)
        val manage = GridLayoutManager(mContext, 5)
        childrenRv.adapter = evaluateChildrenApadter
        childrenRv.layoutManager = manage

    }


}